//
//  CouponTableViewCell.m
//  MyNewProject
//
//  Created by 王春辉 on 2020/1/2.
//  Copyright © 2020年 sun. All rights reserved.
//

#import "CouponTableViewCell.h"

@interface CouponTableViewCell()

@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *limitLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *desLabel;
@property (nonatomic, strong) UIButton *useBtn;
@end
@implementation CouponTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initContentViews];
    }
    return self;
}
- (void)initContentViews {
    UIImageView *imageView = [[UIImageView alloc] initWithImage:SKIMAGE_NAMED(@"mine_coupon_bg_img")];
    [self addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.bottom.mas_offset(0);
    }];
 
    
    UILabel *yuan = [[UILabel alloc] init];
    yuan.text = @"¥";
    yuan.font = SKFONT_SIZE(14);
    yuan.textColor = SKColorWithHex(0xFD6D63);
    [self addSubview:yuan];
    
    [yuan mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageView.mas_left).mas_offset(23);
        make.centerY.mas_equalTo(imageView).mas_offset(0);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(yuan.mas_right).mas_offset(4);
        make.bottom.mas_equalTo(yuan.mas_bottom).mas_offset(6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageView).mas_offset(100);
        make.bottom.mas_equalTo(self.limitLabel.mas_top).mas_offset(-4);
    }];
    
    [self.limitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.bottom.mas_equalTo(imageView.mas_centerY).mas_offset(4);
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.limitLabel.mas_bottom).mas_offset(4);
    }];
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.dateLabel.mas_bottom).mas_offset(4);
    }];
    
    [self.useBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(imageView.mas_right).mas_offset(-26);
        make.centerY.mas_equalTo(imageView);
        make.size.mas_equalTo(CGSizeMake(74, 28));
    }];
}


#pragma mark -- mark 懒加载

- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.font = SKFONT_BOLD_SIZE(30);
        _moneyLabel.textColor = SKColorWithHex(0xFD6D63);
        _moneyLabel.text = @" ";
        [self addSubview:_moneyLabel];
    }
    return _moneyLabel;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.font = SKFONT_Medium(15);
        _titleLabel.textColor = SKColorWithHex(0x333333);
        _titleLabel.text = @" ";
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}
- (UILabel *)limitLabel {
    if (!_limitLabel) {
        self.limitLabel = [[UILabel alloc] init];
        _limitLabel.font = SKFONT_SIZE(13);
        _limitLabel.textColor = SKColorWithHex(0x333333);
        _limitLabel.text = @" ";
        [self addSubview:_limitLabel];
    }
    return _limitLabel;
}
- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.font = SKFONT_SIZE(10);
        _dateLabel.textColor = SKColorWithHex(0x999999);
        _dateLabel.text = @" ";
        [self addSubview:_dateLabel];
    }
    return _dateLabel;
}
- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc] init];
        _desLabel.font = SKFONT_SIZE(10);
        _desLabel.textColor = SKColorWithHex(0x999999);
        _desLabel.text = @" ";
        [self addSubview:_desLabel];
    }
    return _desLabel;
}
- (UIButton *)useBtn {
    if (!_useBtn) {
        _useBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_useBtn setTitle:@"使用" forState:UIControlStateNormal];
        [_useBtn setTitleColor:SKColorWithHex(0xFD6D63) forState:UIControlStateNormal];
        _useBtn.titleLabel.font = SKFONT_SIZE(13);
        _useBtn.layer.masksToBounds = true;
        _useBtn.layer.borderColor = SKColorWithHex(0xFD6D63).CGColor;
        _useBtn.layer.borderWidth = 1.0f;
        [_useBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_useBtn];
    }
    return _useBtn;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    self.useBtn.layer.cornerRadius = self.useBtn.height * 0.5;
}

#pragma mark -- mark 业务逻辑
- (void)setMoney:(CGFloat)money {
    _money = money;
    self.moneyLabel.text = [NSString stringWithFormat:@"%.0f", money];
}
- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}
- (void)setLimit:(NSString *)limit {
    _limit = limit;
    self.limitLabel.text = limit;
}
- (void)setDate:(NSString *)date {
    _date = date;
    self.dateLabel.text = [NSString stringWithFormat:@"有效期至%@", date];
}
- (void)setDes:(NSString *)des {
    _des = des;
    self.desLabel.text = des;
}
#pragma mark -- mark EVENT

- (void)buttonClick:(UIButton *)sender {
    if (self.clickButtonBlock) {
        self.clickButtonBlock(); }
}
@end
